Skip to content

Build XNNPACK as an ExternalProject #12425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Build XNNPACK as an ExternalProject #12425

wants to merge 14 commits into from

Conversation

swolchok
Copy link
Contributor

I believe this is necessary to support EXPORT. (We probably should not
land this unless we have a PR stacked on top of this that successfully
converts the build to EXPORT; sending this out so I can get CI going)

[ghstack-poisoned]
@swolchok
Copy link
Contributor Author

swolchok commented Jul 13, 2025

Stack from ghstack (oldest at bottom):

Copy link

pytorch-bot bot commented Jul 13, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/12425

Note: Links to docs will display an error until the docs builds have been completed.

❌ 114 New Failures, 1 Cancelled Job, 3 Unrelated Failures

As of commit 466f669 with merge base b9bb3c1 (image):

NEW FAILURES - The following jobs have failed:

CANCELLED JOB - The following job was cancelled. Please retry:

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

swolchok added a commit that referenced this pull request Jul 13, 2025
I believe this is necessary to support EXPORT. (We probably should not
land this unless we have a PR stacked on top of this that successfully
converts the build to EXPORT; sending this out so I can get CI going)


ghstack-source-id: 6ce92d7
ghstack-comment-id: 3067161235
Pull-Request: #12425
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 13, 2025
[ghstack-poisoned]
swolchok added a commit that referenced this pull request Jul 13, 2025
I believe this is necessary to support EXPORT. (We probably should not
land this unless we have a PR stacked on top of this that successfully
converts the build to EXPORT; sending this out so I can get CI going)

ghstack-source-id: 0aa08b8
ghstack-comment-id: 3067161235
Pull-Request: #12425
@swolchok swolchok added the release notes: none Do not include this in the release notes label Jul 14, 2025
@swolchok
Copy link
Contributor Author

Apple build is failing because it can't find libXNNPACK.a: https://github.com/pytorch/executorch/actions/runs/16251337270/job/45881437516?pr=12425#step:9:47386

android build is failing because I didn't propagate cross compilation settings to the ExternalProject: https://github.com/pytorch/executorch/actions/runs/16251337288/job/45881440178?pr=12425#step:15:16927

llama runner linux build is failing because CMake is passing -lXNNPACK instead of the path to the static lib. (this happened during debugging before and it was because the XNNPACK target wasn't defined; probably the same again?) https://github.com/pytorch/executorch/actions/runs/16251337288/job/45881439862?pr=12425

unittest failures don't look related but we'll want to keep an eye on them.

@swolchok
Copy link
Contributor Author

I want to see EXPORT work locally before I come back and fix broader platform support, so I'm going to do that first. Converting to draft in the meantime.

@swolchok swolchok marked this pull request as draft July 14, 2025 15:35
swolchok added 5 commits July 14, 2025 11:09
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
swolchok added 2 commits July 14, 2025 16:49
[ghstack-poisoned]
[ghstack-poisoned]
@swolchok
Copy link
Contributor Author

build_frameworks_ios error:

2025-07-15T00:24:13.6245540Z Merging libraries:
2025-07-15T00:24:13.6245660Z libXNNPACK.a
2025-07-15T00:24:13.6245770Z libxnnpack_backend.a
2025-07-15T00:24:13.6245920Z libxnnpack-microkernels-prod.a
2025-07-15T00:24:13.6246060Z from ios/Release
2025-07-15T00:24:13.6246360Z into library /Users/runner/work/executorch/executorch/pytorch/executorch/cmake-out/libbackend_xnnpack_ios.a
2025-07-15T00:24:13.6246770Z File ios/Release/libXNNPACK.a does not exist

Base automatically changed from gh/swolchok/508/head to main July 15, 2025 16:41
swolchok added 2 commits July 15, 2025 11:18
[ghstack-poisoned]
[ghstack-poisoned]
swolchok added a commit that referenced this pull request Jul 15, 2025
As with the previous PR #12425, I think this is needed to get EXPORT
to work.

ghstack-source-id: 2286359
ghstack-comment-id: 3071359023
Pull-Request: #12468
@swolchok swolchok changed the base branch from main to gh/swolchok/510/head July 15, 2025 18:19
swolchok added a commit that referenced this pull request Jul 15, 2025
As with the previous PR #12425, I think this is needed to get EXPORT
to work.

ghstack-source-id: 0f66acd
ghstack-comment-id: 3071359023
Pull-Request: #12468
@swolchok
Copy link
Contributor Author

test-llava-runner-linux failure looks like a flake: https://github.com/pytorch/executorch/actions/runs/16301129189/job/46035741014?pr=12425#step:15:15293 . therefore publishing for review

@swolchok swolchok marked this pull request as ready for review July 15, 2025 19:58
Copy link
Contributor

@mcr229 mcr229 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes in the XNNPACK cmake/dependencies.cmake look good to me

include(cmake/Dependencies.cmake)
set(xnnpack_third_party XNNPACK pthreadpool extension_threadpool cpuinfo)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious what does this rearrangment do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just found it weird that we were mutating xnnpack_third_party in cmake/Dependencies.cmake rather than setting it all at once

Comment on lines +74 to +75
set_target_properties(
XNNPACK PROPERTIES INTERFACE_LINK_LIBRARIES xnnpack-microkernels-prod
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh shoot does this mean that any targets that link XNNPACK will also automatically link xnnpack-microkernels-prod as well? So we don't have to explicitly list both XNNPACK and xnnpack-microkernels-prod? I was trying to figure out how to do this for a while, but never figured it out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

target_link_libraries with visibility PUBLIC or INTERFACE does this for normal libraries, but you need to do it this way for IMPORTED libraries.

LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
add_library(kleidiai SHARED IMPORTED)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think i merged something that might have conflict here. I just added a check

if (TARGET kleidiai)

before adding the library

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be fine I think

swolchok added a commit that referenced this pull request Jul 15, 2025
Following PR (#12425) broke Linux manywheel and there was no way to
repro it on that PR; I just happened to catch it because the PR after
that (#12468) triggered the manywheel build.
Base automatically changed from gh/swolchok/510/head to main July 15, 2025 20:44
[ghstack-poisoned]
@swolchok
Copy link
Contributor Author

bunch of flakes that need to be rerun to make sure but no actual problems in the 7 failures so far

lucylq pushed a commit that referenced this pull request Jul 17, 2025
Following PR (#12425) broke Linux manywheel and there was no way to
repro it on that PR; I just happened to catch it because the PR after
that (#12468) triggered the manywheel build.
@swolchok
Copy link
Contributor Author

Apparently FetchContent is preferred over ExternalProject. The thing I wanted from ExternalProject is separating our build from the dependency's build (i.e., not using add_subdirectory), because the XNNPACK dependency ecosystem doesn't support EXPORT. IIUC, we can get that separation using FetchContent by configuring it to support find_package (using either FIND_PACKAGE_ARGS when we don't require specific changes to or a bleeding-edge version of the dependency, or OVERRIDE_FIND_PACKAGE when we do have such a requirement; both will result in later find_package calls hitting the FetchContent version of the dep, it's just that FIND_PACKAGE_ARGS might find the thing installed system-wide) and then using find_package.

[ghstack-poisoned]
[ghstack-poisoned]
swolchok added a commit that referenced this pull request Jul 18, 2025
I believe this is necessary to support EXPORT. (We probably should not
land this unless we have a PR stacked on top of this that successfully
converts the build to EXPORT; sending this out so I can get CI going)

ghstack-source-id: d179497
ghstack-comment-id: 3067161235
Pull-Request: #12425
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/binaries ciflow/trunk CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. release notes: none Do not include this in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants